﻿// MemoryTest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>

#include "Manager.h"
#include "CloneTest.h"
#include <string>

using namespace std;
void Test01()
{
    UpperClass upperClass1;
    UpperStruct upperStruct1;

    upperClass1.a = 100;
    upperStruct1.a = 200;
    DownClass dc1{1,1,1};
    upperClass1.b = dc1;
    upperStruct1.b = dc1;

    cout << "up1地址：" << (int)&upperClass1 << ";up1大小" << sizeof(upperClass1) << endl;
    cout << "dc1地址：" << (int)&dc1 << ";dc1大小" << sizeof(dc1) << endl;
    cout << "up1-a地址：" << (int)&upperClass1.a << ";up1-a大小" << sizeof(upperClass1.a) << endl;
    cout << "up1-b地址：" << (int)&upperClass1.b << ";up1-b大小" << sizeof(upperClass1.b) << endl;
    cout << "us1地址：" << (int)&upperStruct1 << ";us1大小" << sizeof(upperStruct1) << endl;
    cout << "us1-a地址：" << (int)&upperStruct1.a << ";us1-a大小" << sizeof(upperStruct1.a) << endl;
    cout << "us1-b地址：" << (int)&upperStruct1.b << ";us1-b大小" << sizeof(upperStruct1.b)<<endl;

    cout << "**********************************************************************" << endl;
    UpperClass* upperClass2= new UpperClass();
    UpperStruct* upperStruct2= new UpperStruct();

    upperClass2->a = 100;
    upperStruct2->a = 200;
    DownClass* dc2 = new DownClass();
    upperClass2->b = *dc2;
    upperStruct2->b = *dc2;
    
    cout << "up2地址：" << (int)upperClass2 << ";up2大小" << sizeof(*upperClass2) << endl;
    cout << "dc2地址：" << (int)dc2 << ";dc大小" << sizeof(*dc2) << endl;
    cout << "up2-a地址：" << (int)&upperClass2->a << ";up2-a大小" << sizeof(upperClass2->a) << endl;
    cout << "up2-b地址：" << (int)&upperClass2->b << ";up2-b大小" << sizeof(upperClass2->b) << endl;
    cout << "us2地址：" << (int)upperStruct2 << ";us2大小" << sizeof(*upperStruct2) << endl;
    cout << "us2-a地址：" << (int)&upperStruct2->a << ";us2-a大小" << sizeof(upperStruct2->a) << endl;
    cout << "us2-b地址：" << (int)&upperStruct2->b << ";us2-b大小" << sizeof(upperStruct2->b) << endl;
}

void Test02()
{
    UpperClass upperClass1;
    UpperStruct upperStruct1;

    upperClass1.a = 100;
    upperStruct1.a = 200;

    DownClass* dc1 = new DownClass();

    upperClass1.b = *dc1;
    upperStruct1.b = *dc1;

    cout << "up1地址：" << (int)&upperClass1 << ";up1大小" << sizeof(upperClass1) << endl;
    cout << "dc1地址：" << (int)dc1 << ";dc1大小" << sizeof(*dc1) << endl;
    cout << "up1-a地址：" << (int)&upperClass1.a << ";up1-a大小" << sizeof(upperClass1.a) << endl;
    cout << "up1-b地址：" << (int)&upperClass1.b << ";up1-b大小" << sizeof(upperClass1.b) << endl;
    cout << "us1地址：" << (int)&upperStruct1 << ";us1大小" << sizeof(upperStruct1) << endl;
    cout << "us1-a地址：" << (int)&upperStruct1.a << ";us1-a大小" << sizeof(upperStruct1.a) << endl;
    cout << "us1-b地址：" << (int)&upperStruct1.b << ";us1-b大小" << sizeof(upperStruct1.b) << endl;

    cout << "**********************************************************************" << endl;
    UpperClass* upperClass2 = new UpperClass();
    UpperStruct* upperStruct2 = new UpperStruct();

    upperClass2->a = 100;
    upperStruct2->a = 200;

    DownClass dc2;
    upperClass2->b = dc2;
    upperStruct2->b = dc2;

    cout << "up2地址：" << (int)upperClass2 << ";up2大小" << sizeof(*upperClass2) << endl;
    cout << "dc2地址：" << (int)&dc2 << ";dc大小" << sizeof(dc2) << endl;
    cout << "up2-a地址：" << (int)&upperClass2->a << ";up2-a大小" << sizeof(upperClass2->a) << endl;
    cout << "up2-b地址：" << (int)&upperClass2->b << ";up2-b大小" << sizeof(upperClass2->b) << endl;
    cout << "us2地址：" << (int)upperStruct2 << ";us2大小" << sizeof(*upperStruct2) << endl;
    cout << "us2-a地址：" << (int)&upperStruct2->a << ";us2-a大小" << sizeof(upperStruct2->a) << endl;
    cout << "us2-b地址：" << (int)&upperStruct2->b << ";us2-b大小" << sizeof(upperStruct2->b) << endl;
}

void Test03()
{
    UpperClass upperClass1;
    UpperStruct upperStruct1;

    upperClass1.a = 100;
    upperStruct1.a = 200;

    DownClass* dc1 = new DownTClass();
    DownTClass* dc3 = new DownTClass();

    upperClass1.b = *dc3;
    upperStruct1.b =*dc3;

    cout << "up1地址：" << (int)&upperClass1 << ";up1大小" << sizeof(upperClass1) << endl;
    cout << "dc1地址：" << (int)dc1 << ";dc1大小" << sizeof(*dc1) << endl;
    cout << "dc3地址：" << (int)dc3 << ";dc3大小" << sizeof(*dc3) << endl;
    cout << "up1-a地址：" << (int)&upperClass1.a << ";up1-a大小" << sizeof(upperClass1.a) << endl;
    cout << "up1-b地址：" << (int)&upperClass1.b << ";up1-b大小" << sizeof(upperClass1.b) << endl;
    cout << "us1地址：" << (int)&upperStruct1 << ";us1大小" << sizeof(upperStruct1) << endl;
    cout << "us1-a地址：" << (int)&upperStruct1.a << ";us1-a大小" << sizeof(upperStruct1.a) << endl;
    cout << "us1-b地址：" << (int)&upperStruct1.b << ";us1-b大小" << sizeof(upperStruct1.b) << endl;

    cout << "**********************************************************************" << endl;
    UpperClass* upperClass2 = new UpperClass();
    UpperStruct* upperStruct2 = new UpperStruct();

    upperClass2->a = 100;
    upperStruct2->a = 200;

    DownClass dc2{1,1,1};
    upperClass2->b = dc2;
    upperStruct2->b = dc2;

    cout << "up2地址：" << (int)upperClass2 << ";up2大小" << sizeof(*upperClass2) << endl;
    cout << "dc2地址：" << (int)&dc2 << ";dc大小" << sizeof(dc2) << endl;
    cout << "up2-a地址：" << (int)&upperClass2->a << ";up2-a大小" << sizeof(upperClass2->a) << endl;
    cout << "up2-b地址：" << (int)&upperClass2->b << ";up2-b大小" << sizeof(upperClass2->b) << endl;
    cout << "us2地址：" << (int)upperStruct2 << ";us2大小" << sizeof(*upperStruct2) << endl;
    cout << "us2-a地址：" << (int)&upperStruct2->a << ";us2-a大小" << sizeof(upperStruct2->a) << endl;
    cout << "us2-b地址：" << (int)&upperStruct2->b << ";us2-b大小" << sizeof(upperStruct2->b) << endl;
}

void TestClone()
{
    Teacher p2;
    p2.age = 20;
    p2.name =3;
    p2.school = 4;

    Person& p3 = p2.Clone(p2);

    
    std::cout << "P2地址：" << (int)&p2 << endl;
    std::cout << "P3地址：" << (int)&p3 << endl;

    Teacher p4 = *(Teacher*)(&p3);
    std::cout << "P4地址：" << (int)&p3 << endl;
    std::cout << "P4school：" << p4.school << endl;

}
void TestCloneAdress01()
{
    Teacher p2;
    p2.age = 20;
    p2.name = 3;
    p2.school = 4;
    School school;

    school.teacherList->push_back(p2);
    std::cout << "ori teacher addres：" << (int)&p2 << endl;
    std::cout << "school adress：" << (int)&school << endl;
    std::cout << "teacher list adress：" << (int)school.teacherList << endl;
    std::cout << "teacher adress：" << (int)&school.teacherList->at(0) << endl;
}
void TestCloneAdress02()
{
    Teacher p4;
    p4.age = 210;
    p4.name = 33;
    p4.school = 43;
    School* school= new School();

    school->teacherList->push_back(p4);

    std::cout << "ori teacher addres：" << (int)&p4 << endl;
    std::cout << "school adress：" << (int)school << endl;
    std::cout << "teacher list adress：" << (int)school->teacherList << endl;
    std::cout << "teacher adress：" << (int)&school->teacherList->at(0) << endl;
}

void ReplaceVector()
{
    std::vector<int> sd{ 1,2,3,4,5,6,7,8 };
    for (size_t i = 0; i < sd.size(); i++)
    {
        std::cout << sd[i] << endl;
    }
    sd[0] = 100;
    for (size_t i = 0; i < sd.size(); i++)
    {
        std::cout << sd[i] << endl;
    }
    
}
int main()
{
    //TestClone();
   /* TestCloneAdress01();
    std::cout << "**************************************************"<< endl;
   TestCloneAdress02();*/
    ReplaceVector();
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
